import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Link,browserHistory } from 'react-router';

import { Breadcrumb, Icon,Table,Button } from 'antd';

export default class NavBar extends React.Component {
    constructor(props, context){
        super(props, context);
        this.state={};
    }

    goUrl(url){
      if(url){
        this.context.router.push(url);
      }else{
        browserHistory.goBack()
      }
    }

    render() {
        var {title,navs,back_url} = this.props;
       return (
            <div className='breadcrumb'>
                <Breadcrumb>
                   {/* <Breadcrumb.Item href="/home">
                      <Icon type="home" />首页
                    </Breadcrumb.Item>*/}
                    {navs.map((item,i)=>{
                        if(item.href){
                            return (
                                    <Breadcrumb.Item  
                                      key={i}
                                      onClick={()=>{
                                        browserHistory.push(item.href);
                                      }}
                                    >
                                      <Icon type={item.type} />
                                      <span>{item.title}</span>
                                    </Breadcrumb.Item>
                                )
                        }
                        return (
                            <Breadcrumb.Item key={i}>
                              <Icon type={item.type} />
                              <span>{item.title}</span>
                            </Breadcrumb.Item>
                        )
                        
                    })}
                    
              </Breadcrumb>
              {navs.length>1?
                <Button type="primary" onClick={this.goUrl.bind(this,back_url)} >返回</Button>
                :
                null
              }
              
            </div>
        )
    }
}
NavBar.contextTypes= { router: React.PropTypes.object.isRequired};
